package cn.com.baiwei.controller;

import cn.com.baiwei.pojo.DailyIncomePurchaseProfit;
import cn.com.baiwei.service.impl.DailyIncomePurchaseProfitServiceImpl;
import io.swagger.annotations.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (DailyIncomePurchaseProfit)表控制层
 *
 * @author yangqing
 * @since 2021-09-18 11:06:38
 * @version 1.0
 */
@Component
@RestController
@RequestMapping("/dailyIncomePurchaseProfit")
@Api(value = "(DailyIncomePurchaseProfit)管理",tags = "每日流水（收入、支出、利润）管理接口API")
@ApiResponses({
        @ApiResponse(code=400,message="请求参数不完整或者错误"),
        @ApiResponse(code=404,message="找不到页面"),
        @ApiResponse(code=405,message="请求方式不正确，比如后台接收是post，但前端请求的是get"),
        @ApiResponse(code=406,message="页面地址和接口名冲突"),
        @ApiResponse(code=415,message="请求格式不正确，前端可能没有把请求头修改为json，也可能前端请求的json对象没有转换为字符串"),
        @ApiResponse(code=500,message="后台服务逻辑错误")
})
public class DailyIncomePurchaseProfitController {
    /**
     * 服务对象
     */
    @Resource
    private DailyIncomePurchaseProfitServiceImpl dailyIncomePurchaseProfitServiceImpl;

    /**
     * 通过主键查询单条数据
     * @param index  需要查询的页码
     * @param name   模糊查询的内容
     * @param limit  分页数量
     * @return 单条数据
     */
    @RequestMapping(value = "/selectForPage", method = RequestMethod.GET)
    @ApiOperation(value = "列表查询分页接口",notes = "列表查询分页接口",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",paramType = "query",dataType = "int",required = true,example="1"),
            @ApiImplicitParam(name = "name",value = "(DailyIncomePurchaseProfit)名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "limit",value = "分页数量",paramType = "query",dataType = "int",required = true,example="10")
    })
    public Map<String, Object> selectForPage(@RequestParam(name = "page") int index,@RequestParam(name = "limit") int limit, String name) {
        return this.dailyIncomePurchaseProfitServiceImpl.selectForPage(index, limit, name);
    }
    
    /**
     * 查询所有数据
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll", method = RequestMethod.GET)
    @ApiOperation(value = "查询所有数据接口",notes = "查询所有数据接口",httpMethod = "GET")
    public Map<String, Object> selectAll() {
        return this.dailyIncomePurchaseProfitServiceImpl.selectAll();
    }
    
//    /**
//     * 通过主键删除单条数据
//     *
//     * @param id 主键
//     * @return 单条数据
//     */
//    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
//    @ApiOperation(value = "根据一个id删除一条数据的接口",notes = "根据一个id删除一条数据的接口",httpMethod = "POST")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id",value = "主键",paramType = "query",dataType = "String",required = true),
//    })
//    public Map<String, Object> deleteById(@RequestParam("id") String id) {
//        return this.dailyIncomePurchaseProfitServiceImpl.deleteById(id);
//    }
    
    /**
     * 通过date查询单条数据
     *
     * @param date 日期
     * @return 实例对象
     */
    @RequestMapping(value = "/selectByDate", method = RequestMethod.GET)
    @ApiOperation(value = "通过date查询一个数据的接口",notes = "通过日期（2021-09-11）查询一个数据的接口",httpMethod = "GET")
    public Map<String, Object> selectByDate(String date) {
        return this.dailyIncomePurchaseProfitServiceImpl.selectByDate(date);
    }

    /**
     * 通过开始结束时间查询多个数据
     *
     * @param startDate 开始时间
     * @param endDate 结束时间
     * @return 实例对象
     */
    @RequestMapping(value = "/selectSomeTime", method = RequestMethod.GET)
    @ApiOperation(value = "通过startDate和endDate查询一个数据的接口",notes = "通过一段开始结束日期查询一个数据的接口",httpMethod = "GET")
    public Map<String, Object> selectSomeTime(String startDate,String endDate) {
        return this.dailyIncomePurchaseProfitServiceImpl.selectSomeTime(startDate,endDate);
    }
    
    /**
     * 通过日期更新单条数据
     *
     * @param dailyIncomePurchaseProfit 一个数据库对应的POJO数据对象
     * @return 单条数据
     */
    @RequestMapping(value = "/updateByDate", method = RequestMethod.POST)
    @ApiOperation(value = "通过Date更新一个数据的接口",notes = "通过日期更新一个数据的接口",httpMethod = "POST")
    public Map<String, Object> updateById(@RequestBody @ApiParam(name = "dailyIncomePurchaseProfit",value = "pojo模型",required = true) DailyIncomePurchaseProfit dailyIncomePurchaseProfit) {
        return this.dailyIncomePurchaseProfitServiceImpl.updateByDate(dailyIncomePurchaseProfit);
    }
    
    /**
     * 自动新增单条数据
     *
     */
//    @Scheduled(cron = "0 * 15 * * ?")// 每天下午3点到4点每分钟执行一次
   @Scheduled(cron = "0 59 23 * * ?")//每天23:59分执行
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    @ApiOperation(value = "通过Scheduled注解自动新增数据接口",notes = "通过Scheduled注解自动新增数据接口",httpMethod = "GET")
    public void insert() {
        this.dailyIncomePurchaseProfitServiceImpl.insert();
    }

    /**
     * 通过date查询每日销量
     *
     * @param date 日期
     * @return 实例对象
     */
    @RequestMapping(value = "/selectSalesByDate", method = RequestMethod.GET)
    @ApiOperation(value = "通过date查询每日销量的接口",notes = "通过日期（2021-09-11）查询每日销量的接口",httpMethod = "GET")
    public Map<String, Object> selectSalesByDate(String date) {
        return this.dailyIncomePurchaseProfitServiceImpl.selectSalesByDate(date);
    }

}
